using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using IcecreamView;
using Framework.Audio;

namespace View{

    public class SettingPanel : IcecreamView.IC_AbstractModule
    {
        [BindUIPath("BG/BGMSet")]
        private SliderBinder _bgmSlider;
        [BindUIPath("BG/BSESet")]
        private SliderBinder _bseSlider;
        [BindUIPath("BG/SESet")]
        private SliderBinder _seSlider;

        public override void OnInitView()
        {
            _bgmSlider.OnValueChange += value => { Account.Instance.SettingData.BGMValue = value / 100f; AudioManager.Instance.LoadVolume(); };
            _bseSlider.OnValueChange += value => { Account.Instance.SettingData.BSEValue = value / 100f; AudioManager.Instance.LoadVolume(); };
            _seSlider.OnValueChange += value => { Account.Instance.SettingData.SEValue = value / 100f; AudioManager.Instance.LoadVolume(); };
        }

        public override void OnOpenView(Dictionary<string,IC_ViewData> parameters)
        {
            _bgmSlider.Value = AudioManager.Instance.MusicValue * 100;
            _bseSlider.Value = Account.Instance.SettingData.BSEValue * 100;
            _seSlider.Value = Account.Instance.SettingData.SEValue * 100;
        }

        public override void OnCloseView()
        {
            Account.Instance.Save(Framework.Save.SaveData.GameSetting);
        }

        [BindUIButton("BG/CloseBtn")]
        private void OnClick_Close() 
        {
            AudioManager.Instance.PlaySound("System/ui_btn2");
            ViewConnector.OpenView(UIPanel.HomePanel, true);
        }
    }
}
